package com.CGFrame.Axis;

import java.util.Iterator;

import org.apache.axis.MessageContext;
import org.apache.axis.session.Session;
import org.jdom.Document;
import org.jdom.Element;


import com.CGFrame.struts.POJOs.Task;
import com.CGFrame.struts.bean.reguser.ReguserBean;

public class TasksList {
	public String getTasks(String projectId)
	{
		try
		{
			
			MessageContext mc = MessageContext.getCurrentContext();
			Session session = mc.getSession();
			//session.set("TEST2", "TEST2");
			//	System.out.println( "Session RegUserId "+session.get("RegUserId") ); 
			Element elementRoot = new Element("Result");
			Document document = new Document(elementRoot);
			
			ReguserBean regUserBean = new ReguserBean((String)session.get("RegUserId"));
			Iterator ite_Tasks = regUserBean.getTasksByProject(projectId).iterator();
			
			while( ite_Tasks.hasNext())
			{
				Task task = (Task)ite_Tasks.next();
				Element element;
				if ( task.getMake().getElement() != null )
				{
					element= new Element("ElementTasks");
					element.addAttribute("TaskId", task.getTaskId().toString());
					element.addAttribute("TaskName",task.getTaskName());
					element.addAttribute("Status",task.getStatus().getStatusName());				
				}
				else  
				{
					element = new Element("ShotTasks");
					element.addAttribute("TaskId", task.getTaskId().toString());
					element.addAttribute("TaskName",task.getTaskName());
					element.addAttribute("Status",task.getStatus().getStatusName());
				}
				document.getRootElement().addContent(element);
			}
			
			//	XMLOut out = new XMLOut();
			
			String XMLStr =  XMLOut.outputToString(document);
			//	System.out.println("----------------------");
			//	System.out.println(XMLStr);
			return XMLStr;
		}
		catch(Exception e)
		{
			System.out.println(e);
			return null;
		}
	}

}
